<?php
/**
 * Created by PhpStorm.
 * User: DaibiDaddy
 * Date: 2016/6/3
 * Time: 14:59
 */

namespace App\Setting\LazyCommon;


//use Conf\ConfObject;
use App\Model\LazyCommon\CCM;
use App\Model\LazyCommon\ConfCatModel;

class PlatConfigSetting{

    /*手动获取的配置项*/
    public $entityCnName = "平台配置";//模块名称
    public $table = "Plat_Config";//数据表名称
    public $editKeys = array("orders");//后台管理列表中可以直接编辑的字段
    public $perPage = 100;//后台管理列表中可以直接编辑的字段

    /*自动获取的配置项*/
    public $bundleName;
    public $entityName;
    public $SettingPath;
    public $entityPath;
    public $entity;
    public $modelPath;
    public $em;

    public function __construct($em)
    {
        $this->bundleName = "App";
        $this->entityName = str_replace("\\","",str_replace("Setting","",str_replace(__NAMESPACE__,"",__CLASS__)));
        $this->SettingPath = __CLASS__;
        $this->entityPath = str_replace($this->entityName."Entity",$this->entityName,str_replace("Setting","Entity",str_replace("\\LazyCommon","",__CLASS__)));
        $this->entity = new $this->entityPath();
        $this->modelPath = str_replace("Setting","Model",__CLASS__);
        $this->em = $em;
    }

    public function getDoctrine()
    {
        return $this->em;
    }

    public function listConfig()
    {
        $default = array();
        $default["Plat_Config AS PlatConfig"]["select"] = array("id","category","pic","text","article","orders","tips");
        $default["Plat_Config AS PlatConfig"]["search"] = array();
        $default["Plat_Config AS PlatConfig"]["condition"] = array();
        $default["Plat_Config AS PlatConfig"]["orderBy"] = array("category"=>"ASC");

        $join = array();
        $join["Conf_Cat AS B"]["on"] = "B.id = PlatConfig.category";
        $join["Conf_Cat AS B"]["select"] = array("name","link");
        $join["Conf_Cat AS B"]["search"] = array();
        $join["Conf_Cat AS B"]["condition"] = array();
        $join["Conf_Cat AS B"]["orderBy"] = array();

        $join["Conf_Cat AS A"]["on"] = "A.id = PlatConfig.type";
        $join["Conf_Cat AS A"]["select"] = array("name","link");
        $join["Conf_Cat AS A"]["search"] = array();
        $join["Conf_Cat AS A"]["condition"] = array();
        $join["Conf_Cat AS A"]["orderBy"] = array();

        return array(
            "default"   => $default,
            "joins"     => $join,
        );
    }

    public function formConfig()
    {
        $CCM = new CCM($this->getDoctrine());
        $choice["other"] = array(
            "choices"   => $CCM->getSons4SettingRadio("PlatConfCat"),
        );
        $config["category"] = array(
            "label"     =>"设置类型",
            "showType"  =>"radio",
            "dataType"  =>"required",
            "option"    => $choice
        );
        $choice["other"] = array(
            "choices"   => $CCM->getSons4SettingRadio("PlatConfType"),
        );
        $config["type"] = array(
            "label"     =>"数据类型",
            "showType"  =>"radio",
            "dataType"  =>"required",
            "option"    => $choice
        );
        $config["tips"] = array(
            "label"     =>"说明",
            "showType"  =>"text",
            "dataType"  =>"",
            "option"    => array()
        );
        $config["text"] = array(
            "label"     =>"短文本值",
            "showType"  =>"text",
            "dataType"  =>"",
            "option"    => array()
        );
        $config["article"] = array(
            "label"     =>"富文本值",
            "showType"  =>"article",
            "dataType"  =>"",
            "option"    => array()
        );
        $config["pic"] = array(
            "label"     =>"图片",
            "showType"  =>"pic",
            "dataType"  =>"",
            "option"    => array()
        );

        $config["orders"] = array(
            "label"     =>"排序",
            "showType"  =>"text",
            "dataType"  =>"",
            "option"    => array()
        );
        return $config;
    }
}